<?php

use yii\db\Migration;

class m180418_073528_create_msg_template extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%msg_template}}', [
            'id' => $this->primaryKey(),
            'msg_template_code' => $this->string(100)->unique()->notNull()->comment('模板码唯一'),
            'msg_template_name' => $this->string(100)->defaultValue(null)->comment('模板名称'),
            'sms_text' => $this->text()->defaultValue(null)->comment('短信模型内容'),
            'sms_state' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('是否开启短信'),
            'email_text' => $this->text()->defaultValue(null)->comment('邮件内容'),
            'email_state' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('邮件是否发送'),
            'wechat_text' => $this->text()->defaultValue(null)->comment('微信内容'),
            'wechat_state' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('微信是否发送'),
            'sys_text' => $this->text()->defaultValue(null)->comment('系统消息'),
            'sys_state' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('微信是否发送'),
            'admin_id' => $this->integer()->defaultValue(0)->comment('管理员'),
            'created_at' => $this->integer(11)->defaultValue(0)->notNull()->comment('创建时间'),
        ],$tableOptions);
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->dropTable('{{%msg_template}}');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m180418_073528_create_msg_template cannot be reverted.\n";

        return false;
    }
    */
}
